package com.example.demo_test.Controller;

import com.example.demo_test.DTO.UserAndMessage;
import com.example.demo_test.Entity.*;
import com.example.demo_test.Service.PersonService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author zhanghong
 * @date 2021/4/9  0009 17:56
 */
@RestController
@RequestMapping("/user")
public class PersonController {
    private final static Logger logger = LoggerFactory.getLogger(PersonController.class);
    @Autowired
    private PersonService personService;

    @GetMapping("/login")
    public Result Login(@Param("loginName")String loginName, @Param("password") String password){
        return personService.Login( loginName,password );
    }
    @GetMapping("/register")
    public Result register(@Param("userId")String userId, @Param("password") String password,@Param( "userName" )String userName){
        return personService.register( userId,password,userName );
    }
    @GetMapping("/getFriends")
    public List<User> getFriends(@Param( "userId" )String userId){
        return personService.getFriends( userId );
    }

    @GetMapping("/getUserById")
    public User getUserById(@Param( "userId" )String userId){
        return personService.getUserById(userId);
    }

    @GetMapping("/addFriend")
    public Result addFriend(@Param( "userId" )String userId,@Param( "friendId" )String friendId){
        return personService.addFriend(userId,friendId);
    }
    @GetMapping("/getReqRecordById")
    public List<ReqRecord> getReqRecordById(@Param("userId")String userId){
        return personService.getReqRecordById(userId);
    }
    @PostMapping("/handleReqRecord")
    public Result agreeReqRecord(@RequestBody ReqRecord reqRecord){
        return personService.agreeReqRecord(reqRecord);
    }
    @PostMapping("/updateUser")
    public Result updateUser(@RequestBody User user){
        return personService.updateUser(user);
    }

    @GetMapping("/getFriendsAndMessage")
    public List<UserAndMessage> getFriendsAndMessage(@Param( "userId" )String userId){
        return personService.getFriendsAndMessage(userId);
    }
    @GetMapping("/changePassword")
    public Result changePassword(@Param( "eid" )int eid,@Param( "newPassword" )String newPassword){
        return personService.changePassword(eid,newPassword);
    }
    @GetMapping("deleteFriend")
    public Result deleteFriend(@Param( "userId" )String userId,@Param( "friendId" )String friendId){
        return personService.deleteFriend(userId,friendId);
    }
}
